< previous page page_588 next page >

Page 588
In this routine, you see a lot of calls to the KeySave() method. Also, notice the use of named arguments.
The KeySave() Method in the INI Class
The KeySave() method is very similar to the KeyGet() method in that it receives optional arguments and assigns them to the appropriate module-level variables. Then, the WritePrivateProfileString() function is called. Heres the code:
9f31265bb40b592b1929e18a47ab28e5.gif
Public Sub KeySave(Optional strKeyValue As String = "NA", _
                  Optional strSection As String = "NA", _
                  Optional strKeyName As String = "NA")
   Dim lngRet As Long

   ' Fill in properties
   If strSection <> "NA" Then
      mstrSection = strSection
   End If
   If strKeyName <> "NA" Then
      mstrKeyName = strKeyName
   End If
   If strKeyValue <> "NA" Then
      mstrKeyValue = strKeyValue
   End If

   lngRet = WritePrivateProfileString(mstrSection, _
                                   mstrKeyName, _
                                   mstrKeyValue, _
                                   mstrConfigName)
End Sub
Using the INI Class to Get a Section's Values
Sometimes you might want to retrieve all the key names and key values from one section in an INI file. In this case, you can call the SectionGet() method in the INI class to have it return a Variant array of all the KeyName=KeyValue pairs of data. Heres the code:
9f31265bb40b592b1929e18a47ab28e5.gif
Private Sub cmdAllSettings_Click()
   Dim oIni As INI
   Dim astrKeys As Variant
   Dim intLoop As Integer

 
< previous page page_588 next page >

If you like this book, buy it!